home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-15 | 7.1 KB | 260 lines | [TEXT/MPS ] |
- ;********************************************************************
- ; LAP802.a contains protocol handler routines for IEEE 802.3 LAP.
- ;
- ; (c) Copyright 1990-91 by Apple Computer, Inc. All rights reserved.
- ;
- ;********************************************************************
-
- TITLE 'LAP802'
- CASE OBJ
-
- ;
- ; LAP802.a contains the LAP manager routines for attaching and
- ; detaching the protocol handlers for 802.3 protocols
- ; It contains Lap manager assembler routines.
- ;
- ; 1.2 11/29/90 Rajesh written/modified for IEEE 802.3 LAP
- ; 1/18/88 JEM Initial version
- ;
- INCLUDE 'SysEqu.a'
- INCLUDE 'Traps.a'
-
- LAP802AttachCode EQU 21
- LAP802DetachCode EQU 22
-
- ;
- ; long L802Attach(ProcPtr prot_handler, long ioRefNum, char *protType)
- ;
- ; return 0 if everything is ok else nonzero
- ;
- L802Attach PROC EXPORT
- LAPMgrPtr EQU $B18 ; Entry point for LAP Manager
- LAPMgrCall EQU 2 ; Offset to LAP Manager routines
- ; L802Entry EQU * ; L802 routine entry
- ARG1 SET 8
- ARG2 SET ARG1+4
- ARG3 SET ARG2+4
- move.l a4,-(sp) ; push a4 register
- moveq #LAP802AttachCode,d0 ; move 21 in d0 - attach code
- move.l ARG1(sp),a0 ; put pointer to protocol handler in a0
- move.l ARG2(sp),d2 ; put ioRefNum of driver in d2
- move.l ARG3(sp),a1 ; put the protType pointer in a1
- move.l LAPMgrPtr,a4 ; put pointer to LAP Mgr in a4
- jsr LAPMgrCall(a4) ; jump to start of LAP Mgr routines
- move.l (sp)+,a4 ; pop a4 register
- rts
- ENDPROC
-
- ;
- ; long L802Detach(long ioRefNum, char *protType)
- ;
- ; return 0 if everything is ok else nonzero
- ;
- L802Detach PROC EXPORT
- LAPMgrPtr EQU $B18 ; Entry point for LAP Manager
- LAPMgrCall EQU 2 ; Offset to LAP Manager routines
- ; L802Entry EQU * ; L802 routine entry
- ARG1 SET 8
- ARG2 SET ARG1+4
- move.l a4,-(sp) ; push a4 register
- moveq #LAP802DetachCode,d0 ; move 22 in d0 - detach code
- move.l ARG1(sp),d2 ; put ioRefNum of driver in d2
- move.l ARG2(sp),a1 ; put the protType pointer in a1
- move.l LAPMgrPtr,a4 ; put pointer to LAP Mgr in a4
- jsr LAPMgrCall(a4) ; jump to start of LAP Mgr routines
- move.l (sp)+,a4 ; pop a4 register
- rts
- ENDPROC
-
-
- ;
- ; rdStruct (the read data structure) definition
- ;
- ph_rp EQU 0 ;pointer to "ReadPacket" routine
- ph_rr EQU ph_rp+4 ;pointer to "ReadRest" routine
- ph_bytesleft EQU ph_rr+4 ;number of bytes left to read
- ph_a4 EQU ph_bytesleft+4 ;a4 save area used by driver */
- ph_a0 EQU ph_a4+4 ;a0 save area used by driver */
- ph_a1 EQU ph_a0+4 ;a1 save area used by driver */
- ph_a2 EQU ph_a1+4 ;a2 save area used by driver */
-
- cregs REG d2-d3/a2-a5
-
- ;
- ; GetLAPPtr returns a pointer to the LAP information structure
- ;
-
- PROC
- EXPORT SetLAPPtr, GetLAPPtr
- SetLAPPtr
- ARG1 SET 4 ;LAP_info struct ptr (char *)
- lea.l LapPtr(PC),a0
- move.l ARG1(sp),(a0)
- rts
-
- GetLAPPtr
- move.l LapPtr(PC),d0
- rts
-
- LapPtr dc.l 0 ;pointer to LAP variable storage
- ENDPROC
-
- ;
- ; GetA5Ptr returns a pointer to the driver global variables
- ;
-
- GetA5Ptr PROC EXPORT
- move.l A5Ptr,d0
- rts
-
- A5Ptr dc.l 0 ;pointer to global variables
- ENDPROC
-
- ;
- ; OSErr ReadPacket(rds,ptr,cnt)
- ; struct rdStruct *rds;
- ; char * ptr;
- ; int cnt;
- ;
- ; ReadPacket is called by the link-layer to setup the registers from the
- ; read data structure and call the ReadPacket entry point
- ;
-
- ReadPacket PROC EXPORT
- movem.l cregs, -(sp)
- ARG1 SET 6*4 + 4 ;&rds (struct rdStruct *)
- ARG2 SET ARG1+4 ;user buffer ptr (char *)
- ARG3 SET ARG2+4 ;bytes to read (int)
- move.l ARG1(sp), d2 ;get PH register save block
- move.l d2,a4
- movem.l ph_a0(a4), a0-a2 ;restore a0, a1 & a2
- move.l ph_bytesleft(a4), d1 ;restore D1
- move.l ARG2(sp), a3 ;setup buffer pointer
- move.l ARG3(sp), d3 ;and byte count
- move.l ph_a4(a4),a4
- jsr (a4) ;call read packet
- beq.s @1 ;no SCC errors
- move.l #-1,d3 ;indicate error condition
- clr.l d1 ;no bytes left to read
- @1 move.w d3, d0 ;get return code
- ext.l d0 ;convert to long
- move.l ARG1(sp), a4 ;get PH register save block
- movem.l a0-a2, ph_a0(a4) ;save updated a0, a1 & a2
- move.l d1, ph_bytesleft(a4) ;save new D1
- movem.l (sp)+, cregs
- rts
- ENDPROC
-
-
- ; OSErr ReadRest(rds, ptr, cnt)
- ; struct rds *rds;
- ; char * ptr;
- ; int cnt;
- ;
- ; ReadRest is called to read in the rest of the packet from the Ethernet
- ; driver. FALSE is returned if the buffer was too small. */
-
- ReadRest PROC EXPORT
- movem.l cregs, -(sp)
- ARG1 SET 6*4 + 4 ;&rds (struct rdStruct *)
- ARG2 SET ARG1+4 ;user buffer ptr (char *)
- ARG3 SET ARG2+4 ;maximum bytes to read (int)
- move.l ARG1(sp), d2 ;get PH register save block
- move.l d2,a4
- movem.l ph_a0(a4), a0-a2 ;restore a0, a1 & a2
- move.l ph_bytesleft(a4), d1 ;restore D1
- move.l ARG2(sp), a3 ;setup buffer pointer
- move.l ARG3(sp), d3 ;and byte count
- move.l ph_a4(a4),a4
- jsr 2(a4) ;call read rest
- beq.s @1 ;no SCC errors
- move.l #-1,d3 ;indicate error condition
- clr.l d1 ;no bytes left to read
- @1 lea.l A4Saved(PC), A0 ;restore A4 for app see Inside Mac II-326 third to the last para.
- move.l A4, (A0)
- move.w d3, d0 ;get return code
- ext.l d0 ;convert to long
- move.l ARG1(sp), a4 ;get PH register save block
- movem.l a0-a2, ph_a0(a4) ;save updated a0, a1 & a2
- move.l d1, ph_bytesleft(a4) ;save new D1
- movem.l (sp)+, cregs
- rts
-
- EXPORT SetUpRDS, SetBuffer, ReadBuffered, Lap802p3_ph
- IMPORT Lap802_read_ph
-
- ;
- ; Ptr SetUpRDS(rds)
- ; struct rdStruct *rds
- ;
- ; SetUpRDS is called from a protocol listener to set-up the read
- ; data structure in a form than can be used later by C routines
- ; It returns the address of the link header already read-in.
- ;
- SetUpRDS
- move.l a5, -(sp)
- ARG1 SET 1*4 + 4 ;&rds (struct rdStruct *)
- move.l ARG1(sp), a5 ;Get RDS pointer
- movem.l a0-a2,ph_a0(a5) ;save away a0, a1 & a2
- move.l a4,ph_a4(a5)
- lea.l ReadPacket,a0
- move.l a0,ph_rp(a5)
- lea.l ReadRest,a0
- move.l a0,ph_rr(a5)
- ext.l d1 ;convert bytes-left to long
- move.l d1,ph_bytesleft(a5)
- move.l a3,d0
- move.l (sp)+, a5
- rts
- ;
- ; void SetBuffer(buf, len)
- ; Ptr buf
- ; Int len
- ;
-
- SetBuffer
- ARG1 SET 4
- ARG2 SET ARG1+4
- lea.l BuffPtr(PC),a0
- move.l ARG1(sp),(a0)
- lea.l BuffLen(PC),a0
- move.l ARG2(sp),(a0)
- rts
-
-
- BuffPtr dc.l 0 ;pointer to LAP packet buffer
- BuffLen dc.l 0 ;length of LAP buffer
-
- A4Saved dc.l 0 ;pointer to apps A4
-
- Lap802p3_ph
- jsr Lap802_read_ph
- move.l A4Saved(PC), A4
- rts
- ;
- ; ReadBuffered is called instead of SetUp and ReadRest to immediate begin
- ; reading data from the LAP into a fixed LAP buffer. SetBufPtr must be
- ; called during initialization to specify the location and size of the buffer
-
- ReadBuffered
- ;
- ; On Call - A0-a2 setup for AppleTalk
- ;
- ; Returns: D0 - Number of bytes in Packet or -1 if LocalTalk error
- ;
-
- move.l BuffPtr(PC),a3 ;setup buffer pointer
- move.l BuffLen(PC),d3 ;and byte count
- ext.l d1
- move.l d1,-(sp) ;save size of packet
- jsr 2(a4) ;call ReadRest
- beq.s @1 ;no SCC errors
- ; _Debugger
- move.l #-1,(sp) ;indicate error condition
- @1 lea.l A4Saved(PC), A0
- move.l A4, (A0)
- move.l (sp)+,d0 ;return number of bytes in packet
- rts
- ENDPROC
- END
-